<?php
/**
 * Created by Allen.
 * User: Allen
 * Date: 15-10-22
 */

class Appoint_model extends HS_Model {

	
    //获取结果集
    public function getAppointList($where=array(), $limit='20', $offset='0', $order_by='appoint.id desc')
    {
    	return $this->select('appoint.*,user.user_nick,user.address,user.areas,vehicle.car_num,vehicle.vehicle_owner')
    	->join('user','user.id = appoint.user_id')
    	->join('vehicle','vehicle.id = appoint.vehicle_id')
    	->where($where)->limit($limit, $offset)->order_by($order_by)->find_all();
    }
    
    //计算行数
    public function getCount($where = array())
    {
    	return $this->select('appoint.*,user.user_nick,user.address,user.areas,vehicle.car_num,vehicle.vehicle_owner')
    	->join('user','user.id = appoint.user_id')
    	->join('vehicle','vehicle.id = appoint.vehicle_id')
    	->where($where)->count();
    }  
     
    //获取单个
    public function checkAppoint($where = array())
    {
    	return $this->select('appoint.*,user.user_nick,user.address,user.areas,vehicle.car_num,vehicle.vehicle_owner,vehicle.phone,vehicle.card_num')
    	->join('user','user.id = appoint.user_id')
    	->join('vehicle','vehicle.id = appoint.vehicle_id')
    	->where($where)->find();
    }

    //删除
    public function deleteAppoint($where)
    {
    	return $this->where($where)->delete();
    }
    
    //编辑
    public function editAppoint($where,$data)
    {
    	return $this->where($where)->edit($data);
    }
    
    //添加
    public function addAppoint($data)
    {
    	if ($this->add($data))
    	{
    		return $this->db->insert_id();
    	}
    } 
    
    //订单信息
    public function appointInfo($where = array())
    {
    	return $this->select('vehicle.*,vehicle.company_name as cp_name,appoint.*')
    	->join('vehicle','vehicle.id = appoint.vehicle_id')
    	->where($where)->find();
    }   
    
    //会员订单信息
    public function appointUser($where = array(),$order_by = 'id desc')
    {
    	return $this->select('vehicle.*,vehicle.company_name as cp_name,appoint.*')
    	->join('vehicle','vehicle.id = appoint.vehicle_id')
    	->where($where)->find_all();
    }
} 